<!--
@name:tabRiskAssessment
@author:Zhenglei
@date:14:12
@description:tabRiskAssessment
@update:2022/7/1314:12
-->
<template>
  <div class="pd-20">

    <el-button type="primary"
               @click="handleOption('add')">新增
    </el-button>
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData"
                   v-loading="loading">
      <template v-slot:option="{row}">
        <el-button type="primary"
                   @click="handleOption('edit', row)">编辑
        </el-button>
        <el-button type="danger"
                   @click="handleOption('del', row)">删除
        </el-button>
      </template>
    </element-table>
    <dialog-risk v-if="showDialog" :visible.sync="showDialog" :dataObj="dataObj"/>
  </div>

</template>

<script>
import ElementTable from "../../../../base/ElementTable";
import dialogRiskAssessment from "./dialogRiskAssessment";

export default {
  name: "tabRiskAssessment",
  data() {
    return {

      tableData: [],
      loading: false,
      showDialog: false,
      dataObj: {},
      columns: [
        {
          label: '风险等级',
          prop: 'rank',
          align: 'center',
          formatter: (row, cellValue) => {
            if (row.rank === 1) return '低风险'
            if (row.rank === 2) return '中低风险'
            if (row.rank === 3) return '中风险'
            if (row.rank === 4) return '中高风险'
            if (row.rank === 5) return '高风险'
            if (row.rank === 6) return '超高风险'
          },
        },{
          label: '判断条件',
          prop: 'rule',
          align: 'center',
        },{
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true
        }
      ],

    }
  },
  created() {
    this.getList()
  },

  methods: {
    getList() {
      this.loading = true
      this.post(this.api.healthMap.getBodyRiskList).then((res) => {
        this.loading = false
        if (res.data.code === '200') {
          this.tableData = res.data.object
          this.pageTotal = res.data.object.totalNum
        }
      })
    },
    handleOption(op, row) {
      switch (op) {
        case 'add':
          this.dataObj = {}
          this.showDialog = true
          break;
        case 'edit':
          this.dataObj = row
          this.showDialog = true
          break
        case 'select':
          this.pageIndex = 1
          this.getList();
          break
        case 'del':
          this.$confirm('是否要确认?', '提示', {
            type: 'warning'
          }).then(() => {
            this.post(this.api.healthMap.delBodyRisk, {
              rank: row.rank
            }).then((res) => {
              if (res.data.code === '200') {
                this.$message.success('删除成功!');
                this.getList()
              }
            })
          })
          break

      }

    },

  },
  components: {
    'element-table': ElementTable,
    'dialog-risk':dialogRiskAssessment
  }
}
</script>

<style scoped>
.common-table {
  padding-bottom: 0;
}
.view-save{
  position: fixed;
  bottom: 20px;
}
</style>
